<template>
	<view class="container">
		<u-navbar back-icon-color="#FFFFFF" :background="{ background: 'linear-gradient(to right, #A36BFF 0%, #6D4BBE 100%)' }" :border-bottom="false" title="我的佣金" title-color="#FFFFFF"></u-navbar>
		<view class="commission-head">
			<image class="commission-head__image" src="../../../static/icons/icon_commission.png" mode="aspectFit"></image>
			<view class="commission-head__left">
				<text>{{account.money}}</text>
				佣金总额（元）
			</view>
			<u-button @click="bindWithdraw()" class="commission-head__btn" type="default" size="mini" shape="circle" :custom-style="{width:'140rpx',color:'#fff',background:'rgba(0,0,0,0)'}">去提现</u-button>
		</view>
		<!-- mescroll-body start -->
		<mescroll-body ref="mescrollRef" :down="downOption" :up="upOption" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="commission-list">
				<view class="commission-list__item" v-for="(log,index) in moneyList" :key="index">
					<view class="commission-list__left">
						<view class="title" v-if="log.extra_text.type == 1">{{log.extra_text.nickname}}-{{log.memo}}</view>
						<view class="title" v-else>{{log.memo}}</view>
						<view class="time">{{log.createtime_text}}</view>
					</view>
					<view class="commission-list__right">
						<text :class="(log.money>0?'plus':'minus')" >￥{{log.money}}</text>
					</view>
				</view>
			</view>
		</mescroll-body>
		<!-- mescroll-body end -->
		
	</view>
</template>

<script>
	// 引入mescroll-mixins.js
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				account:{
					money: '0.00',
					total_money: '0.00',
					freeze_money: '0.00'
				},
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon: '../../../../static/images/icon_empty-class.png',
						tip: '暂无最新活动哦'
					}
				},
				moneyList:[]
			}
		},
		onLoad() {
			this.fetchAccount();
		},
		methods: {
			fetchAccount(){
				this.$core.post({url: 'fitness.user/account',data: {},success: ret => {
						this.account = ret.data;
					},fail: err => {
						uni.showModal({
							title: '提示',
							content: err.msg,
							showCancel:false,
							success(){
								uni.navigateBack()
							}
						})
					}
				});
			},
			
			/*上拉加载的回调*/
			upCallback(page) {
				var that = this;
				let shop = that.$core.getCurrentShop();
				let shopId = shop ? shop.id : 0;
				that.$core.post({url:'fitness.user/money_lists',data:{page:page.num,pagesize:page.size},success:(ret)=>{
					if(page.num == 1) that.moneyList = []; //如果是第一页需手动制空列表
					that.moneyList = that.moneyList.concat(ret.data.data); //追加新数据
					that.mescroll.endSuccess(ret.data.data.length);
				}});
			},
			
			bindWithdraw(){
				uni.navigateTo({
					url: '/pages/my/cashOut/cashOut',
					events: {
					    withdrawSuccess: data => {
					        this.fetchAccount();
							this.mescroll.resetUpScroll();
					    }
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.commission-head {
		position: relative;
		display: flex;
		align-items: center;
		padding: 24rpx;
		padding-bottom: 48rpx;
		height: 200rpx;
		background: linear-gradient(to right, #A36BFF 0%, #6D4BBE 100%);
		overflow: hidden;
		&__image {
			position: absolute;
			top: 0;
			right: 0;
			display: block;
			width: 188rpx;
			height: 200rpx;
		}
		&__left {
			flex: 1;
			padding: 0 24rpx;
			overflow: hidden;
			line-height: 38rpx;
			font-size: 26rpx;
			color: #FFFFFF;
			text {
				display: block;
				line-height: 68rpx;
				font-size: 48rpx;
				font-weight: 600;
				color: #FFFFFF;
			}
		}
		&__btn {
			position: relative;
			z-index: 9;
		}
	}
	.commission-list {
		position: relative;
		margin-top: -24rpx;
		padding: 0 24rpx;
		border-radius: 24rpx;
		background: #FFFFFF;
		&__item {
			display: flex;
			align-items: center;
			border-bottom: 1rpx #EDEDED solid;
			padding: 32rpx 0;
		}
		&__left {
			flex: 1;
			overflow: hidden;
			.title {
				line-height: 40rpx;
				font-size: 28rpx;
				color: #191919;
			}
			.time {
				margin-top: 8rpx;
				line-height: 34rpx;
				font-size: 24rpx;
				color: #999999;
			}
		}
		&__right {
			line-height: 40rpx;
			font-size: 28rpx;
			font-weight: 500;
			.plus {
				color: #F00000;
			}
			.minus {
				color: #00B620;
			}
		}
	}
</style>